package org.linuxsogood.boot.queue;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author liu.hongwei
 * @since 2020/4/27 14:46
 */
@Slf4j
public class QueueFactory {


    public static void main(String[] args) throws InterruptedException {
        DelayQueue<Message> delayeds = new DelayQueue<>();
        final MoveAction moveAction = new MoveAction(0);
        delayeds.add(new Message(moveAction, moveAction.getStartSeconds(), TimeUnit.SECONDS));

        final LightBeltAction lightBeltAction1 = new LightBeltAction(0);
        delayeds.add(new Message(lightBeltAction1, lightBeltAction1.getStartSeconds(), TimeUnit.SECONDS));

        final AudioAction audioAction = new AudioAction(3);
        delayeds.add(new Message(audioAction, audioAction.getStartSeconds(), TimeUnit.SECONDS));

        final PicAction picAction = new PicAction(2);
        delayeds.add(new Message(picAction, picAction.getStartSeconds(), TimeUnit.SECONDS));

        final TextBroadcastAction textBroadcastAction = new TextBroadcastAction(5);
        delayeds.add(new Message(textBroadcastAction, textBroadcastAction.getStartSeconds(), TimeUnit.SECONDS));


        final LightBeltAction lightBeltAction = new LightBeltAction(5);
        delayeds.add(new Message(lightBeltAction, lightBeltAction.getStartSeconds(), TimeUnit.SECONDS));

        while (!delayeds.isEmpty()) {
            final Message take = delayeds.take();
            take.getMsg().execute();
        }


    }


}
